package jmine.tec.report.cell.impl;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;

import jmine.tec.report.cell.DataCell;

/**
 * @author adalberto
 */
public class StringDataCell implements DataCell, Serializable {

    private static final long serialVersionUID = 1L;

    private final String value;

    private final boolean resolve;

    /**
     * @param value the value
     * @param resolve if <code>true</code>, the value should be resolved against a bundle
     */
    public StringDataCell(final String value, final boolean resolve) {
        super();
        this.value = value;
        this.resolve = resolve;
    }

    /**
     * Construtor
     * 
     * @param value String
     */
    public StringDataCell(final String value) {
        this(value, true);
    }

    /**
     * Retorna null pois n�o faz sentido
     * 
     * @return Date
     */
    public Date toDate() {
        return null;
    }

    /**
     * Retorna not a number
     * 
     * @return Double
     */
    public Double toDouble() {
        return Double.valueOf(0.0);
    }

    /**
     * Retorna o valor em forma de String sem formata��o.
     * 
     * @return String
     */
    @Override
    public String toString() {
        return this.value;
    }

    /**
     * Retorna a String
     * 
     * @param dateFormat DateFormat
     * @param doubleFormat NumberFormat
     * @param currencyFormat NumberFormat
     * @return String
     */
    public String toString(final DateFormat dateFormat, final NumberFormat doubleFormat, final NumberFormat currencyFormat) {

        return this.value;
    }

    /**
     * Compara este DataCell � outro Retorna um inteiro menor, igual ou maior que zero se esta instancia for inferior, igual ou maior que o
     * parametro.
     * 
     * @param o DataCell
     * @return int
     */
    public int compareTo(final DataCell o) {
        return this.toString().compareTo(o.toString());
    }

    /**
     * @return the value
     */
    public String getValue() {
        return this.value;
    }

    /**
     * @return int
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        final int trueHash = 1231;
        final int falseHash = 1237;
        result = prime * result + (this.resolve ? trueHash : falseHash);
        result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
        return result;
    }

    /**
     * @param obj the object
     * @return boolean
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (this.getClass() != obj.getClass()) {
            return false;
        }
        final StringDataCell other = (StringDataCell) obj;
        if (this.resolve != other.resolve) {
            return false;
        }
        if (this.value == null) {
            if (other.value != null) {
                return false;
            }
        } else if (!this.value.equals(other.value)) {
            return false;
        }
        return true;
    }

    /**
     * @return the resolve
     */
    public boolean isResolve() {
        return this.resolve;
    }

    /**
     * {@inheritDoc}
     */
    public String format() {
        return this.toString();
    }
}
